<?php
	####################################################
	# library import and object instance.              #
	####################################################
	# 커먼 인클루드
	include_once( '../common.php' );

	####################################################
	# request data($_POST AND $_GET FROM $_REQUEST)    #
	####################################################
	# REQUEST(get and post variables)
	$req = Request::clean_request($_REQUEST, FALSE);

	# GET(url variables)

	# POST(form variables)

	# Validation(special case validate)
	//Nlog::xmp($req['muid']);
	if(!is_numeric($req['muid'])) Mover::error();

	####################################################
	# implementation                                   #
	####################################################
	$sec->individual_access();
	$sec->run_cookie_check();

	$modules_name = $appm->get_module_name($req['muid']);
	if(empty($modules_name)){
		Mover::error();
	}

	$packages_keys = $appm->get_packages_key(0, $db->getcnts('ggo_cfg_packages_pref'));

	$modules = $appm->get_module_package($req['muid']);
	$modules_has_key = array();
	foreach($modules as $key=>$val){
		$modules_has_key[] = $val['puid'];
	}


	//Nlog::xmp($packages_keys);
	//Nlog::puts('modules',$modules);
?>
<?php
	# HTML START
	echo $html->custom_header(TITLE);
	echo $tplt->page_construct_javascript();
	echo $html->custom_js("{$JS}common.js");
	echo $html->custom_css("{$CSS}common.css");
	echo $html->custom_body();
?>
	<?php $tplt->app_head($NAVI)?>
	<?php $tplt->tiles_admin_sidebar($NAVI)?>
	<?php $tplt->tiles_admin_contents($pkname, $pname, $pdesc)?>

		<h4>'<?=$modules_name?>'에 연결된 패키지를 관리합니다.</h4>
		<?php echo NForm::open(NULL, FALSE, "list");?>
			<?php echo NForm::mode('linkage', sprintf("%s?muid=%s",$PHP_SELF,$req['muid']));?>
			<?php echo NForm::hidden('muid', $req['muid']);?>
			<table class="tbl" border="0" cellpadding="0" cellspacing="0">
				<colgroup>
					<col width="40" />
					<col width="40" />
					<col width="*" />
					<col width="*" />
				</colgroup>
				<tr>
					<th><input type="checkbox" id="chkctr1" onclick="CheckboxControl.toggle_check_all('#chkctr1','.chk1');"/></th>
					<th>번호</th>
					<th>패키지 이름</th>
					<th>패키지 키</th>
				</tr>
				<?php foreach($packages_keys['res'] as $key=>$val) :?>
				<tr>
					<td>
						<input type="checkbox" name="map[]" id="chk1_<?=$val['puid']?>" class="chk1" value="<?=$val['puid']?>"
							<?php if(in_array($val['puid'], $modules_has_key)):?>checked="checked"<?php endif;?>
						/>
					</td>
					<td><?php if(in_array($val['puid'], $modules_has_key)):?>√ <?php endif;?><?=$val['puid']?></td>
					<td><?=$val['packages_name']?></td>
					<td><?=$val['packages_key']?></td>
				</tr>
				<?php endforeach;?>
			</table>
			<?php echo NForm::close();?>
			<div class="tblt">
			</div>
		<div class="tblh">
			체크된 패키지를 : <span class="cbtn_s" onclick="$('#formx_list').submit();">연결</span>&nbsp;
			<span class="cbtn_s" onclick="Mover.href('admin.modules.manager')">취소</span>&nbsp;
		</div>
<?php
	# HTML END
	echo $tplt->tiles_admin_footer();
	echo $tplt->page_destruct_javascript();
	include_once( '../endproc.php' );
	echo $html->html_footer();
?>